package com.studyroom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.studyroom.entity.Snack;
import com.studyroom.mapper.SnackMapper;
import com.studyroom.service.SnackService;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class SnackServiceImpl extends ServiceImpl<SnackMapper, Snack> implements SnackService {
    
    @Override
    public Page<Snack> getSnackPage(Page<Snack> page, 
                                   String name,
                                   Double minPrice,
                                   Double maxPrice,
                                   Integer minStock,
                                   Integer maxStock,
                                   Integer status) {
        return baseMapper.selectSnackPage(page, name, minPrice, maxPrice, minStock, maxStock, status);
    }

    @Override
    public List<Snack> getAvailableSnacks() {
        LambdaQueryWrapper<Snack> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Snack::getStatus, 1)  // 只查询上架的零食
              .gt(Snack::getStock, 0)    // 库存大于0
              .orderByDesc(Snack::getCreatedAt);
        return list(wrapper);
    }
} 